package com.创建型模式.原型模式;


/**
 * 奖状原型
 */
class Citation implements Cloneable{
    private String name;
    private String clazz;//班级
    private String level;//等级
    private String school;//学校
    Citation(String name,String clazz,String level,String school){
        System.out.println("发奖成功");
        this.name = name;
        this.clazz=clazz;
        this.level = level;
        this.school = school;
    }
    public Object clone(){
        Citation citation = null;
        try {
            System.out.println("奖状克隆成功");
            citation = (Citation) super.clone();
        } catch (CloneNotSupportedException e) {
            String.format("奖状克隆失败:%s",e.getMessage());
        }
        return  citation;
    }
    @Override
    public String toString() {
        return "Citation{" +

                "name='" + name + '\'' +
                ", clazz='" + clazz + '\'' +
                ", level='" + level + '\'' +
                ", school='" + school + '\'' +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getClazz() {
        return clazz;
    }

    public void setClazz(String clazz) {
        this.clazz = clazz;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

}
/**
 * 奖状
 */
public class PrototypeCitation {
    public static void main(String[] args) {
        Citation citation = new Citation("张三"
                ,"三年四班"
                ,"日批奖"
                ,"日批学校");
        System.out.println(citation.toString());
        Citation c2 = (Citation) citation.clone();
        c2.setName("李四");
        System.out.println(c2.toString());

    }
}
